package com.xh.bussiness.course.controller;

import com.xh.bussiness.course.bean.request.CourseChapterRequest;
import com.xh.bussiness.course.model.Course;
import com.xh.bussiness.course.model.CourseChapter;
import com.xh.bussiness.course.service.ICourseChapterService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags="课次绑定章节接口")
@RestController
@RequestMapping("/courseChapter")
public class CourseChapterController {

    @Autowired
    ICourseChapterService courseChapterService;

    @RequestMapping("/queryAll")
    public AjaxResult queryAll(@RequestBody  CourseChapterRequest request){
        if(StringUtils.isEmpty(request.getCourseIndexId())){
           return new AjaxResult(AjaxResultConstant.Result.ERROR,"参数错误");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,courseChapterService.queryAll(request));
    }


    @RequestMapping("/add")
    public AjaxResult add(@RequestBody CourseChapterRequest request){
        if(StringUtils.isEmpty(request.getCourseIndexId())){
            return new AjaxResult(AjaxResultConstant.Result.ERROR,"参数错误");
        }
        boolean flag = courseChapterService.add(request);
        if(flag){
            return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"保存成功");
        }
        return new AjaxResult(AjaxResultConstant.Result.ERROR,"保存失败");
    }

    @RequestMapping("/deleteByCourseIndexId")
    @ApiOperation("删除课程课次知识点")
    public AjaxResult deleteByCourseIndexId(String courseIndexId, String chapterId) {
        return new AjaxResult(courseChapterService.deleteByCourseIndexId(courseIndexId, chapterId));
    }
}
